using System;
using System.Windows;

namespace ibba.src.sl.recursos.Validations
{
	public abstract class ValidationService : DependencyObject
	{
		public static ValidationBase GetValidator(DependencyObject obj)
		{
			return (ValidationBase)obj.GetValue(ValidatorProperty);
		}

		public static void SetValidator(DependencyObject obj, ValidationBase value)
		{
			obj.SetValue(ValidatorProperty, value);
		}
		
		// Using a DependencyProperty as the backing store for Validator.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty ValidatorProperty =
			DependencyProperty.RegisterAttached("Validator", typeof(ValidationBase), typeof(ValidationService), new PropertyMetadata(ValidatorsPropertyChangedCallback));

		private static void ValidatorsPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			var v = e.NewValue as ValidationBase;
			if (String.IsNullOrEmpty(v.ManagerName))
			{
				System.Diagnostics.Debug.WriteLine("Required Property 'ManagerName' required for Validator");
				throw new Exception("Required Property 'ManagerName' required for Validator");
			}

			v.Initialize(d as FrameworkElement);
		}
	}
}
